//
//  OtherAnimationViewController.m
//  iOSHeartAnimation
//
//  Created by ddy on 2018/8/13.
//  Copyright © 2018年 ddy. All rights reserved.
//

#import "OtherAnimationViewController.h"

@interface OtherAnimationViewController ()
/** <#something#> */
@property (nonatomic, strong) UIButton  *button;
@end

@implementation OtherAnimationViewController
/**  */
- (UIButton *)button{
    if(!_button){
        _button = [UIButton buttonWithType:UIButtonTypeCustom];
        [_button setImage:[UIImage imageNamed:@"1.jpg"] forState:UIControlStateNormal];
        _button.frame = CGRectMake(100, 150, 100, 100);
        
    }
    return  _button;
}
-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:self.button];
    
    
    
}
- (void)setAnimation {
//    CABasicAnimation *anim = [CABasicAnimation animation];
//    anim.keyPath = @"transform.scale";
//    anim.toValue = @(0.8f);
//    anim.duration = 1.f;
//    anim.speed = 2.0;
//    anim.repeatCount = 1;
//    anim.autoreverses = YES;
//    anim.removedOnCompletion = NO;
//    anim.fillMode = kCAFillModeForwards;
//
//    [self.button.layer addAnimation:anim forKey:nil];
    CASpringAnimation *anim = [CASpringAnimation animationWithKeyPath:@"bounds"];
    anim.damping = 100.0;
    anim.stiffness = 2000.0;
    anim.mass = 5.0;
    anim.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionDefault];
    anim.duration = anim.settlingDuration;
    anim.initialVelocity = 10.0;
    anim.removedOnCompletion = NO;
    anim.byValue = [NSValue valueWithCGRect:CGRectMake(100,350, 110, 110)];
    anim.fillMode = kCAFillModeForwards;
    
    [self.button.layer addAnimation:anim forKey:nil];
}
-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
    
    [self setAnimation];
}
@end
